home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
graphics
/
qrt.lzh
/
TECHMAN.DOC
< prev
next >
Wrap
Text File
|
1989-02-16
|
19KB
|
529 lines
QRT Technical Reference
INTRODUCTION
The QRT ray tracing system has been designed to make the code
easily maintainable and expandable. An object oriented design
philosophy was used for the program, and the resulting code has
been made as robust as practical given time constraints.
This document explains the design of QRT. First, the function of
each QRT C file will be listed. Next, the QRT data structures
will be explained, and finally, some details of code
implementation discussed.
QRT C CODE FILES
The QRT code is broken down into 16 C files and 3 header files,
each containing a group of related functions. The files are, in
alphabetical order:
FILE FUNCTION
bbox.c bounding box intersection routines
error.c error reporting routines
inout.c recursive decent input parser
instance.c file for INSTANCE primitives
intersect.c object intersection routines
lexer.c simple lexical analyzer
mth.c vector math support
norm.c normal finding functions for objects
offset.c offsets a primitive by dx, dy, dz
pattern.c finds pattern info for objects
patternio.c auxiliary parser for patterns
precomp.c pre-computes some info for objects
qrt.c main routine and initialization code
ray.c actual ray tracing algorithims
relpos.c finds relative position on an object
resize.c resize any primitive
stack.c stack and object creation routines
header.h instantiations of some global variables
pattern.h pattern info
qrt.h data structure definitions
The function of each group of routines will be discussed in
greater detail in rest of this document.
QRT Ray Tracer Page 1 Technical Reference
DATA STRUCTURES
All QRT data structures are defined in qrt.h. This file is
broken down into sections, as follows:
OBJECT TYPE DEFINITIONS:
C #define statements for each object type (sphere, lamp,
observer, etc).
MISC DEFINES
Other #defines for screen size, etc.
VECTOR data structure
A floating point 3-tuple vector definition.
COLOR VECTOR data structure
A red,green,blue integer 3-tuple structure.
COLOR INFO structure
This is an important structure. It lists color information for
an object, including ambient and diffuse light
characteristics, reflection and transmission data, Phong
specular reflection coefficient, index of refraction, and
object dithering data.
PRECOMPUTE structure
This contains some fields which can be filled with precomputed
information before the ray-tracing is begun. This saves time
by eliminating redundant calculations for every line/object
intersection. The use of these fields is up to the
intersection routines. Each object also has a 'precompute'
routine which fills this structure.
PATTERN structure
The pattern definition structure contains a color info
structure. It is used to change the characteristics of a
primitive object over the surface of that object. For
example, checkered, brick, or tile patterns may be defined.
OBJECT structure
The base structure of QRT. All objects are defined as an
object structure. This structure contains:
A) A location vector for the object
B) 3 directional vectors
C) The object type flag
D) Some constants for QUADRATIC objects
E) A color info structure
F) Sibling and child pointers for the object tree
G) A pointer to a pattern structure
QRT Ray Tracer Page 2 Technical Reference
H) x and y multipliers for pattern sizing
I) A name field for the object
WORLD structure
This structure contains all data about the world. It contains
pointers to the object tree, the lamp list, the observer, and
the sky, and the pattern stack. It also contains statistic
information, such as total number of rays traced, and the
output file name and pointer.
OBJECT_DATA structure
The header.h file contains an array of this structure, one
array element per object type. The structure itself contains
pointers to functions that perform known operations on object
structures. This design allows much cleaner code and easier
addition of object types. The object function pointers are:
ColTest: Tests for object collisions
FindNorm: Finds normal to surface at a given position
FindBbox: Computes size of bounding box for object
RelPos: Finds relative position on object surface
given a position in space
PreComp: Stuffs 'precomp' structure for each object
before ray-tracing is begun. The precomp and
intersect routines must agree on the exact usage
of the fields in this structure.
Offset: Moves a primitive by dx, dy, dz. This is used
for instances.
Resize: Resizes a primitive ( and scales its location
vector). This is also used for instances.
This structure permits expressions such as:
(*(ObjData[CurrObj->type].ColTest))(line,Currobj,&t);
which means:
(collision func for this obj type )(parameters);
instead of a large case statement. Execution is faster, and
if new objects are added, the code does not have to be
changed. If a certain operation is illegal for a certain
object type, the ObjData entry points to an Err() function.
This way, if something goes wrong, execution is terminated
gracefully instead of jumping to a random location in memory.
QRT Ray Tracer Page 3 Technical Reference
MATH defines
MIN, MAX, SQRT, DotProd macros
DEFAULT structure
Keeps default color information
ERROR codes
Defines for all possible error conditions
ROBUST flag
There are many sections of code of the form:
# ifdef ROBUST
code
# endif
such that, if ROBUST is defined, the bounds-checking code will
be compiled. It is recommended that this flag be always set,
although SLIGHTLY faster execution is possible with it reset.
CODE DESCRIPTION
The function of each section of code will be described in more
detail here.
BBOX.C